package me.ingxin.android.permission2.view

import android.content.Context

/**
 * Created on 2023/7/8 by yin
 * 引导对话框管理
 */
abstract class Guide {

    internal fun getShowReasonView(
        context: Context,
        permissions: List<String>,
        continueBlock: (GuideView) -> Unit,
        interruptBlock: (GuideView) -> Unit
    ): GuideView {
        return createReasonView(context, permissions).initArgument(
            continueBlock, interruptBlock
        )
    }

    internal fun getToSettingsView(
        context: Context,
        permissions: List<String>,
        continueBlock: (GuideView) -> Unit,
        interruptBlock: (GuideView) -> Unit
    ): GuideView {
        return createToSettingsView(context, permissions).initArgument(
            continueBlock, interruptBlock
        )
    }

    internal fun getTipsView(
        context: Context,
        permissions: List<String>,
    ): GuideView {
        return createTipsView(context, permissions).apply { disableCancelable() }
    }

    private fun GuideView.initArgument(
        continueBlock: (GuideView) -> Unit, interruptBlock: (GuideView) -> Unit
    ): GuideView {
        disableCancelable()
        this.continueBlock = continueBlock
        this.interruptBlock = interruptBlock
        return this
    }

    /**
     * 创建展示申请理由的引导对话框
     * @param context 上下文
     * @param permissions 需要申请的权限
     */
    abstract fun createReasonView(
        context: Context, permissions: List<String>
    ): GuideView

    /**
     * 创建前往设置中心的引导对话框
     * @param context 上下文
     * @param permissions 需要前往设置中心手动开启的权限
     */
    abstract fun createToSettingsView(
        context: Context, permissions: List<String>
    ): GuideView

    /**
     * 创建理由对话框，该对话框会在申请普通权限的时候同步显现
     * @param context 上下文
     * @param permissions 需要申请的普通权限
     */
    abstract fun createTipsView(
        context: Context, permissions: List<String>
    ): GuideView

}